import { request } from '@umijs/max';
import { BaseResponse, PageInfo } from '@/golbal';
import { UserType } from '@/models/user';

/***
 * 分页获取用户列表
 * @param params
 */
export async function listUserByPage(params: UserType.UserQueryRequest) {
  return request<BaseResponse<PageInfo<UserType.UserVO[]>>>('/user/list/page', {
    method: 'GET',
    params,
  });
}

/***
 * 创建用户
 * @param params
 */
export async function addUser(params: UserType.UserAddRequest) {
  return request<BaseResponse<PageInfo<UserType.UserVO[]>>>('/user/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 *  根据id获取用户
 */
export async function getUser(params: UserType.GetUser) {
  return request<BaseResponse<PageInfo<UserType.UserVO[]>>>('/user/get', {
    method: 'GET',
    data: params,
  });
}

/***
 *更新用户
 */
export async function updateUser(params: UserType.UserUpdateRequest) {
  return request<BaseResponse<boolean>>('/user/update', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 删除用户
 */
export async function deleteUser(params: UserType.UserDeleteRequest) {
  return request<BaseResponse<boolean>>('/user/delete', {
    method: 'POST',
    params: { ...params },
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 登录接口
 * @param params
 */
export async function userLogin(params: UserType.UserLoginRequest) {
  return request<BaseResponse<UserType.UserVO>>('/user/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 注册接口
 * @param params
 */
export async function userRegister(params: UserType.UserLoginRequest) {
  return request<BaseResponse<UserType.UserVO>>('/user/register', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 *  获取当前登录用户
 */
export async function getLoginUser() {
  return request<BaseResponse<UserType.UserVO>>('/user/get/login', {
    method: 'GET',
  });
}

/***
 * 用户注销
 */
export async function userLogout() {
  return request<BaseResponse<UserType.UserVO>>('/user/logout', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {},
  });
}

/***
 * 用户 更新（修改信息）
 */
export async function renewUser(params: UserType.UserRenewRequest) {
  return request<BaseResponse<number>>('/user/renew/user', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data:params,
  });
}

